home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / doc / SetVar.3 < prev    next >
Text File  |  1993-02-14  |  6KB  |  155 lines

  1. '\"
  2. '\" Copyright 1989 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. .so man.macros
  11. .HS Tcl_SetVar tcl
  12. .BS
  13. .VS
  14. .SH NAME
  15. Tcl_SetVar, Tcl_SetVar2, Tcl_GetVar, Tcl_GetVar2, Tcl_UnsetVar, Tcl_UnsetVar2 \- manipulate Tcl variables
  16. .SH SYNOPSIS
  17. .nf
  18. \fB#include <tcl.h>\fR
  19. .sp
  20. char *
  21. \fBTcl_SetVar\fR(\fIinterp, varName, newValue, flags\fR)
  22. .sp
  23. char *
  24. \fBTcl_SetVar2\fR(\fIinterp, name1, name2, newValue, flags\fR)
  25. .sp
  26. char *
  27. \fBTcl_GetVar\fR(\fIinterp, varName, flags\fR)
  28. .sp
  29. char *
  30. \fBTcl_GetVar2\fR(\fIinterp, name1, name2, flags\fR)
  31. .sp
  32. int
  33. \fBTcl_UnsetVar\fR(\fIinterp, varName, flags\fR)
  34. .sp
  35. int
  36. \fBTcl_UnsetVar2\fR(\fIinterp, name1, name2, flags\fR)
  37. .SH ARGUMENTS
  38. .AS Tcl_Interp *newValue
  39. .AP Tcl_Interp *interp in
  40. Interpreter containing variable.
  41. .AP char *varName in
  42. Name of variable.  May refer to a scalar variable or an element of
  43. an array variable.
  44. .AP char *newValue in
  45. New value for variable.
  46. .AP int flags in
  47. OR-ed combination of bits providing additional information for
  48. operation. See below for valid values.
  49. .AP char *name1 in
  50. Name of scalar variable, or name of array variable if \fIname2\fR
  51. is non-NULL.
  52. .AP char *name2 in
  53. If non-NULL, gives name of element within array and \fIname1\fR
  54. must refer to an array variable.
  55. .BE
  56.  
  57. .SH DESCRIPTION
  58. .PP
  59. These procedures may be used to create, modify, read, and delete
  60. Tcl variables from C code.
  61. \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR will create a new variable
  62. or modify an existing one.
  63. Both of these procedures set the given variable to the value
  64. given by \fInewValue\fR, and they return a pointer to a
  65. copy of the variable's new value, which is stored in Tcl's
  66. variable structure.
  67. Tcl keeps a private copy of the variable's value, so the caller
  68. may change \fInewValue\fR after these procedures return without
  69. affecting the value of the variable.
  70. If an error occurs in setting the variable (e.g. an array
  71. variable is referenced without giving an index into the array),
  72. then NULL is returned.
  73. .PP
  74. The name of the variable may be specified in either of two ways.
  75. If \fBTcl_SetVar\fR is called, the variable name is given as
  76. a single string, \fIvarName\fR.
  77. If \fIvarName\fR contains an open parenthesis and ends with a
  78. close parenthesis, then the value between the parentheses is
  79. treated as an index (which can have any string value) and
  80. the characters before the first open
  81. parenthesis are treated as the name of an array variable.
  82. If \fIvarName\fR doesn't have parentheses as described above, then
  83. the entire string is treated as the name of a scalar variable.
  84. If \fBTcl_SetVar2\fR is called, then the array name and index
  85. have been separated by the caller into two separate strings,
  86. \fIname1\fR and \fIname2\fR respectively;  if \fIname2\fR is
  87. zero it means that a scalar variable is being referenced.
  88. .PP
  89. The \fIflags\fR argument may be used to specify any of several
  90. options to the procedures.
  91. It consists of an OR-ed combination of any of the following
  92. bits:
  93. .IP TCL_GLOBAL_ONLY
  94. Under normal circumstances the procedures look up variables
  95. at the current level of procedure call for \fIinterp\fR, or
  96. at global level if there is no call active.
  97. However, if this bit is set in \fIflags\fR then the variable
  98. is looked up at global level even if there is a procedure
  99. call active.
  100. .IP TCL_LEAVE_ERR_MSG
  101. If an error is returned and this bit is set in \fIflags\fR, then
  102. an error message will be left in \fI\%interp->result\fR.  If this
  103. flag bit isn't set then no error message is left (\fI\%interp->result\fR
  104. will not be modified).
  105. .IP TCL_APPEND_VALUE
  106. If this bit is set then \fInewValue\fR is appended to the current
  107. value, instead of replacing it.
  108. If the variable is currently undefined, then this bit is ignored.
  109. .IP TCL_LIST_ELEMENT
  110. If this bit is set, then \fInewValue\fR is converted to a valid
  111. Tcl list element before setting (or appending to) the variable.
  112. If the list element is being appended to an non-empty value, then
  113. a space character is appended before the new list element to
  114. separate it from previous elements.
  115. .IP TCL_NO_SPACE
  116. If this bit is set, it prevents the output of a separating space
  117. character in TCL_LIST_ELEMENT appends.
  118. This bit has no effect if the TCL_LIST_ELEMENT bit isn't set.
  119. .PP
  120. \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR return the current value
  121. of a variable.
  122. The arguments to these procedures are treated in the same way
  123. as the arguments to \fBTcl_SetVar\fR and \fBTcl_SetVar2\fR.
  124. Under normal circumstances, the return value is a pointer
  125. to the variable's value (which is stored in Tcl's variable
  126. structure and will not change before the next call to \fBTcl_SetVar\fR
  127. or \fBTcl_SetVar2\fR).
  128. The only bits of \fIflags\fR that are used are TCL_GLOBAL_ONLY
  129. and TCL_LEAVE_ERR_MSG, both of
  130. which have
  131. the same meaning as for \fBTcl_SetVar\fR.
  132. If an error occurs in reading the variable (e.g. the variable
  133. doesn't exist or an array element is specified for a scalar
  134. variable), then NULL is returned.
  135. .PP
  136. \fBTcl_UnsetVar\fR and \fBTcl_UnsetVar2\fR may be used to remove
  137. a variable, so that future calls to \fBTcl_GetVar\fR or \fBTcl_GetVar2\fR
  138. for the variable will return an error.
  139. The arguments to these procedures are treated in the same way
  140. as the arguments to \fBTcl_GetVar\fR and \fBTcl_GetVar2\fR.
  141. If the variable is successfully removed then 0 is returned.
  142. If the variable cannot be removed because it doesn't exist
  143. or because a trace is active for it, then -1 is returned.
  144. If an array element is specified, the given element is removed
  145. but the array remains.
  146. If an array name is specified without an index, then the entire
  147. array is removed.
  148.  
  149. .SH "SEE ALSO"
  150. Tcl_TraceVar
  151.  
  152. .SH KEYWORDS
  153. array, interpreter, scalar, set, unset, variable
  154. .VE
  155.